package base016

import (
	"fmt"
	"strconv"
	"strings"
)

func ChangeType(){
	a := 5.0
	// 转换为int类型
	b := int(a)
	//int 转换成string
	str := strconv.Itoa(b) + "666"
	//bool 转换成string
	str1 := strconv.FormatBool(false)
	//字符串转换成 int
	ints, _ := strconv.Atoi("666")

	fmt.Println(b,str,str1,ints)
}

func BaseInfo()  {
	fmt.Println("BaseInfo")

	var str = "  hello nIO null exception "
	var str2 = "sda sda--das dsa//aqq qq//www--ee--111"

	//判断以指定字符开头
	top := strings.HasPrefix(str, "hello")
	//判断以字符结尾
	end := strings.HasSuffix(str, "hello")
	//字符首次出现位置(没有返回-1)
	firstIndex := strings.Index(str, "n")
	//字符最后出现位置(没有返回-1)
	lastIndex := strings.LastIndex(str, "n")
	//字符串替换 -1代表多少位置后替换（全替换）
	newStr := strings.Replace(str,"n","--",-1)

	//转为小写
	lower := strings.ToLower(str)
	//转为大写
	upper := strings.ToUpper(str)

	//在字符串中出现多少次
	repeatCount := strings.Count(str, "n")
	//字符串 重复n次显示
	repeatStr := strings.Repeat(str, 2)

	//去除首尾空白
	space := strings.TrimSpace(str)
	//去除首尾指定字符
	trim1 := strings.Trim(str, "  hello")
	trim2 := strings.TrimLeft(str, "  hello")
	trim3 := strings.TrimRight(str, "  hello")

	//截取 转换成数组
	array1 := strings.Split(str2,"--")

	//连接字符串
	join := strings.Join(array1, "￥￥")

	fmt.Println(top,end,firstIndex,lastIndex)
	fmt.Println(newStr,lower,upper)
	fmt.Println(repeatCount,repeatStr)
	fmt.Println(space,trim1,trim2,trim3)
	fmt.Println(array1)
	fmt.Println(join)
}